/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 8/9/13
 * Time: 9:39 AM
 * To change this template use File | Settings | File Templates.
 */
package societyGames.codeAlong.model.validators
{
import mx.validators.ValidationResult;
import mx.validators.Validator;

public class XMLValidator extends Validator
{
  // Define Array for the return value of doValidation().
  private var results:Array;

  // Constructor.
  public function XMLValidator()
  {
    // Call base class constructor.
    super();
  }

  // Define the doValidation() method.
  override protected function doValidation(value:Object):Array
  {
    // Call base class doValidation().
    results = super.doValidation(value);
    // Return if there are errors.
    if (results.length > 0)
    {
      return results;
    }

    // Clear results Array.
    results.length = 0;

    // Try cast value to XML.
    try
    {
      var xml:XML = XML(String(value));
    }
    catch (typeError:TypeError)
    {
      //handle error
      results.push(new ValidationResult(true, null, "NaN", "You must enter valid XML."));
    }
    return results;
  }
}
}
